/**
 * Created by liaoxd on 2017/12/17.
 */
yufp.require.require('libs/tinymce/tinymce.min.js');
define([
  './themes/lang/' + window.YUFP_SYS_CONFIG.language + '/pages/content/systemManager/notice/notice.js',
  './custom/widgets/js/ElTinymceX.js',
  './custom/widgets/js/yufpOrgTree.js',
  './custom/widgets/js/yufpUploadTable.js',
  './custom/widgets/js/yufpExtTree.js'
], function (require, exports) {
  // page加载完成后调用ready方法
  exports.ready = function (hashCode, data, cite) {
    yufp.lookup.reg('PUB_STS,YESNO,NOTICE_LEVEL');
    // 创建virtual Notice model
    var vm = yufp.custom.vue({
      // TODO 请替换此id属性
      el: cite.el,
      // 以m_开头的属性为UI数据不作为业务数据，否则为业务数据
      data: function () {
        var me = this;
        return {
          a: '',
          // 公告查询URL
          serviceUrl: backend.noticeService + '/api/adminsmnotice/',
          // 角色列表URL
          contrUrl: backend.appOcaService + '/api/provider/findrolelist',
          reciveOptions: [{
            'key': 'org',
            'value': this.$t('notice.jg')
          }, {
            'key': 'role',
            'value': this.$t('notice.js')
          }],
          idView: false,
          tinymceId: 'tinymceEditor',
          // 限制不可选择之前日期
          datePick: {
            disabledDate: function (time) {
              return time.getTime() < Date.now() - 8.64e7;
            }
          },
          // 生成的公告ID
          createdNoticeId: '',

          // 富文本编辑器附件URL
          action: '/api/file/provider/richedituploadfile',
          // 富文本编辑器文本
          content: '',
          tinymceDisabled: false,
          // 富文本操作附件ID传参
          busNo: '',
          height: yufp.custom.viewSize().height - 120,
          userId: yufp.session.userId,
          userName: yufp.session.userName,
          orgId: yufp.session.org.id,
          orgName: yufp.session.org.name,
          creatorFlag: true, // 登录者是否本人
          buttonEnable: false, // 是否可以修改、删除
          // 机构树多选参数
          orgTreeParams: {
            needCheckbox: true
          },
          // 附件列表按钮
          uploadVisible: true,
          downloadVisible: true,
          deleteVisible: true,

          // 弹出窗保存按钮
          createButton: false,
          updateButton: false,
          noticeSelection: null, // 表格选中数据

          // 初始化查询时，传入接收对象
          initTableParams: {
            condition: JSON.stringify({
              reciveOgjId: yufp.session.org.id,
              creatorId: yufp.session.userId,
              userId: yufp.session.userId,
              roles: yufp.session.roles
            })
          },
          // 初始化角色列表
          initRolesTableParams: {
            condition: JSON.stringify({
              orgIds: yufp.session.org.id
            })

          },

          // 初始化附件列表查询时，传入为空
          initFilesParams: {
            condition: JSON.stringify({
              busNo: ''
            })
          },

          noticeUpLoadBusNo: {},
          formdata: {},
          pickerStartOptions: {
            disabledDate: function (time) {
              if (me.formdata.endTime) {
                return (
                  time.getTime() > new Date(me.formdata.endTime).getTime()
                );
              }
            }
          },
          pickerEndOptions: {
            disabledDate: function (time) {
              if (me.formdata.beginTime) {
                return (
                  time.getTime() < new Date(me.formdata.beginTime).getTime()
                );
              }
            }
          },
          tableColumns: [
            {
              label: this.$t('notice.ggbt'),
              prop: 'noticeTitle'
            },
            {
              label: this.$t('notice.fbzt'),
              prop: 'pubSts',
              width: 100,
              resizable: true,
              type: 'select',
              dataCode: 'PUB_STS'
            },
            {
              label: this.$t('notice.ydbz'),
              prop: 'readSts',
              width: 100
            },
            {
              label: this.$t('notice.zycd'),
              prop: 'noticeLevel',
              width: 100,
              type: 'select',
              dataCode: 'NOTICE_LEVEL'
            },
            {
              label: this.$t('notice.fbrq'),
              prop: 'pubTime',
              width: 150
            },
            {
              label: this.$t('notice.fbjg'),
              prop: 'pubOrgName',
              width: 160
            },
            {
              label: this.$t('notice.fbr'),
              prop: 'pubUserName',
              width: 164
            },
            {
              label: this.$t('notice.zdsjz'),
              prop: 'topActiveDate',
              width: 164
            },
            {
              label: this.$t('notice.yxsjz'),
              prop: 'activeDate',
              width: 160
            }
          ],


          updateFields: [{
            columnCount: 1,
            fields: [{
              field: 'noticeTitle',
              label: this.$t('notice.ggbt'),
              rules: [{
                required: true,
                message: this.$t('notice.btx'),
                trigger: 'blur'
              }]
            }]
          },
          {
            columnCount: 2,
            fields: [{
              field: 'noticeLevel',
              label: this.$t('notice.zycd'),
              type: 'select',
              dataCode: 'NOTICE_LEVEL',
              value: 'N'
            },
            {
              field: 'activeDate',
              label: this.$t('notice.yxsj'),
              type: 'date',
              editable: false,
              pickerOptions: 'datePick'
            },
            {
              field: 'isTop',
              label: this.$t('notice.sfzd'),
              type: 'select',
              dataCode: 'YESNO',
              rules: [{
                required: true,
                message: this.$t('notice.btx'),
                trigger: 'blur'
              }],
              change: function (isTop) {
                if (isTop == 'Y') {
                  me.$refs.noticeForm.switch('topActiveDate', 'disabled', false);
                } else {
                  me.$refs.noticeForm.switch('topActiveDate', 'disabled', true);
                }
              }
            },
            {
              field: 'topActiveDate',
              label: this.$t('notice.zdqz'),
              type: 'date',
              editable: false,
              pickerOptions: 'datePick'
            },
            {
              field: 'reciveOrgId',
              label: this.$t('notice.jsjg'),
              params: {
                lazy: false,
                dataId: 'orgId',
                needCheckbox: true,
                checkStrictly: true,
                dataParams: {
                  orgSts: 'A'
                }
              },
              type: 'custom',
              is: 'yufp-org-tree',
              readonly: true,
              hidden: false
            },
            {
              field: 'reciveRoleName',
              label: this.$t('notice.js'),
              focus: function (event) {
                var reciveOrgId = me.$refs.noticeForm.formModel.reciveOrgId;
                me.initRolesTableParams = {
                  condition: JSON.stringify({
                    orgIds: reciveOrgId && reciveOrgId != 'NA' ? reciveOrgId : yufp.session.org.id
                  })
                };
                me.roleDialogVisible = true;
              },
              hidden: false,
              readonly: true,
              icon: 'circle-close',
              click: function () {
                me.$refs.noticeForm.formModel.reciveRoleName = '';
                me.$refs.noticeForm.formModel.reciveRoleId = '';
              }
            },
            {
              field: 'reciveRoleId',
              label: this.$t('notice.js'),
              icon: 'search',
              click: function () {
                me.roleDialogVisible = true;
              },
              hidden: true
            }
            ]
          }
          ],
          updateButtons: [{
            label: this.$t('notice.bc'),
            type: 'primary',
            op: 'submit',
            hidden: true,
            click: function (model, valid) {
              me.$refs.noticeForm.$children[0].validate(function (validate) {
                if (validate) {
                  me.createNotice();
                }
              });
            }
          },
          {
            label: this.$t('notice.bc'),
            type: 'primary',
            hidden: true,
            op: 'submit',
            click: function (model, valid) {
              if (valid) {
                me.dataNoticeEditFn();
              }
            }
          },
          {
            label: this.$t('notice.qx'),
            hidden: false,
            click: function (model) {
              me.dialogVisible = false;
              window.tinymce.get(me.tinymceId).destroy();
            }
          }
          ],
          // 角色选择列表
          roleTableColumns: [{
            label: this.$t('notice.jsdm'),
            prop: 'roleCode'
          }, {
            label: this.$t('notice.jsmc'),
            prop: 'roleName'
          }, {
            label: this.$t('notice.ssjgbh'),
            prop: 'orgId'
          }, {
            label: this.$t('notice.ssjgmc'),
            prop: 'orgName'
          }

          ],

          // 角色选择按钮
          selectionButton: [{
            label: this.$t('notice.qrxz'),
            type: 'primary',
            hidden: false,
            click: function (model) {
              var values = '';
              var names = '';
              me.tablePage = me.$refs.roleTable.page;
              if (me.$refs.roleTable.selections.length >= 0) {
                me.roleSelection = me.$refs.roleTable.selections;
                me.pageChange();
              }
              if (me.roleAllSelect.length > 0) {
                for (var i = 0; i < me.roleAllSelect.length; i++) {
                  if (i == 0) {
                    values = me.roleAllSelect[i].row.roleId;
                    names = me.roleAllSelect[i].row.roleName;
                  } else {
                    values = values + ',' + me.roleAllSelect[i].row.roleId;
                    names = names + ',' + me.roleAllSelect[i].row.roleName;
                  }
                }
              }

              me.$refs.noticeForm.formModel.reciveRoleId = values;
              me.$refs.noticeForm.formModel.reciveRoleName = names;
              me.roleDialogVisible = false;
            }
          },
          {
            label: this.$t('notice.qx'),
            hidden: false,
            click: function (model) {
              me.roleDialogVisible = false;
            }
          }
          ],


          // 表单是否显示
          dialogVisible: false,
          detaildialogVisible: false,
          roleDialogVisible: false,
          // 表单是否可用
          formDisabled: true,
          // 表单操作状态
          viewType: 'DETAIL',

          NoticeGrid: {
            // 权限模板当前行
            currentRow: null,
            // 权限模板选择数组
            selections: [],
            data: null,
            loading: true
          },
          roleSelection: [],
          roleAllSelect: [],
          tablePage: 0
        };
      },
      methods: {
        startChangeFn: function (val) {
          this.NoticeGrid.paging.page = val;
          this.queryNoticeGridFn();
        },
        limitChangeFn: function (val) {
          this.NoticeGrid.paging.page = 1;
          this.NoticeGrid.paging.pageSize = val;
          this.queryNoticeGridFn();
        },
        // 角色表格选中事件
        roleSelectFn: function (selection, row) {
          this.tablePage = this.$refs.roleTable.page;
          this.roleSelection = selection;
        },
        // 角色表格全选事件
        roleAllFn: function (selection) {
          this.tablePage = this.$refs.roleTable.page;
          this.roleSelection = selection;
        },
        // 角色表格翻页事件
        pageChange: function () {
          var me = this;
          if (me.roleAllSelect.length > 0) {
            for (var i = 0; i < me.roleAllSelect.length; i++) {
              if (me.roleAllSelect[i].page == this.tablePage) {
                me.roleAllSelect.splice(i, 1);
                i--;
              }
            }
          }
          if (me.roleSelection.length > 0) {
            for (var j = 0; j < me.roleSelection.length; j++) {
              me.roleAllSelect.push({
                page: me.tablePage,
                row: me.roleSelection[j]
              });
            }
          }
          me.tablePage = 0;
          me.roleSelection = [];
        },
        // 角色数据加载完成后勾选列表
        loadedFn: function (a, b) {
          var me = this;
          me.roleAllSelect.forEach(function (value, index, array) {
            me.$refs.roleTable.data.filter(function (item) {
              if (item.roleId === array[index].row.roleId) {
                me.$refs.roleTable.toggleRowSelection(item, true);
              }
            });
          });
        },
        noticeClickFn: function (selection, row) {
          // 用于单个修改
          this.NoticeGrid.currentRow = selection;
          this.noticeSelection = selection;
        },
        // 修改按钮
        noticetableEditFn: function () {
          if (this.$refs.noticeTable.selections.length < 1) {
            vm.$message({
              message: vm.$t('notice.qxzytjlxg')
            });
            return false;
          }
          if (this.$refs.noticeTable.selections.length > 1) {
            vm.$message({
              message: vm.$t('notice.znxzytjlxg')
            });
            return false;
          }
          this.viewType = 'UPDATE';
          vm.dialogVisible = true;
          this.roleAllSelect = [];
          var noticeId = '';

          yufp.service.request({
            url: backend.noticeService + '/api/adminsmnotice/noticeinfo/' + this.$refs.noticeTable.selections[0].noticeId,
            method: 'get',
            data: null,
            callback: function (code, message, response) {
              if (code == '0' && response.code == 0) {
                vm.$nextTick(function () {
                  vm.$refs.noticeForm.resetFn();
                  yufp.extend(vm.$refs.noticeForm.formModel, response.data);
                  vm.$refs.tinymce.hasChange = false;
                  vm.content = response.data.detailcontent;
                  vm.$refs.tinymce.init();
                  noticeId = response.data.noticeId;

                  // 富文本附件操作传参
                  vm.busNo = noticeId;

                  // 初始化附件列表查询时，传入为空
                  var files = {
                    condition: JSON.stringify({
                      busNo: noticeId
                    })
                  };
                  yufp.extend(vm.initFilesParams, files);
                  // 获取附件列表
                  vm.$refs.filesTable.queryFn(files);

                  // 设置附件列表组件传入NOTICEID
                  vm.noticeUpLoadBusNo = {
                    busNo: response.data.noticeId
                  };
                });
              } else {
                vm.$message({
                  message: vm.$t('notice.hqxqsb')
                });
              }
            }
          });
        },

        // 角色展示
        roleShow: function () {
          this.$nextTick(function () {
            this.$refs.roleTable.remoteData();
          });
        },

        // 详情按钮
        detailFn: function () {
          if (this.$refs.noticeTable.selections.length < 1) {
            vm.$message({
              message: vm.$t('notice.qxzytjlzk')
            });
            return false;
          }
          if (this.$refs.noticeTable.selections.length > 1) {
            vm.$message({
              message: vm.$t('notice.znxzytjlzk')
            });
            return false;
          }
          this.viewType = 'DETAIL';
          vm.dialogVisible = true;
          var noticeId = '';

          yufp.service.request({
            url: backend.noticeService + '/api/adminsmnotice/noticeinfo/' + this.$refs.noticeTable.selections[0].noticeId,
            method: 'get',
            data: null,
            callback: function (code, message, response) {
              if (code == '0' && response.code == 0) {
                vm.$nextTick(function () {
                  vm.uploadVisible = false;
                  vm.downloadVisible = true;
                  vm.deleteVisible = false;
                  vm.$refs.noticeForm.resetFn();
                  yufp.extend(vm.$refs.noticeForm.formModel, response.data);
                  vm.content = response.data.detailcontent;
                  vm.$refs.tinymce.hasChange = false;
                  vm.$refs.tinymce.init();
                  noticeId = response.data.noticeId;
                  // 初始化附件列表查询时，传入noticeId
                  var files = {
                    condition: JSON.stringify({
                      busNo: noticeId
                    })
                  };
                  yufp.extend(vm.initFilesParams, files);
                  // 获取附件列表
                  vm.$refs.filesTable.queryFn(files);

                  // 设置附件列表组件传入NOTICEID
                  vm.noticeUpLoadBusNo = {
                    busNo: response.data.noticeId
                  };
                  // 标为已阅,并刷新公告列表
                  vm.readFn();
                  vm.$refs.noticeTable.remoteData();
                  window.tinymce.get(vm.tinymceId).setMode('readonly');
                });
              } else {
                vm.$message({
                  message: vm.$t('notice.hqxqsb')
                });
              }
            }
          });
        },

        // 已阅按钮
        readButtonFn: function () {
          // 标为已阅,并刷新公告列表
          vm.readFn();
        },

        // 阅读记录
        readFn: function () {
          var selections = this.$refs.noticeTable.selections;
          if (selections.length == 0) {
            this.$message({
              message: this.$t('notice.qxxzjl'),
              type: 'warning'
            });
            return;
          }
          var count = 0;
          var commitData = [];
          for (var i = 0; i < selections.length; i++) {
            if (selections[i].readSts == this.$t('notice.yy')) {
              count++;
            } else {
              selections[i].readUserId = this.userId;
              commitData.push(selections[i]);
            }
          }
          if (commitData.length > 0) {
            yufp.service.request({
              url: backend.noticeService + '/api/adminsmnotice/reads',
              method: 'post',
              data: JSON.stringify(commitData),
              callback: function (code, message, response) {
                if (code == '0' && response.code == 0) {
                  count == 0 ? vm.$message({
                    message: vm.$t('notice.yy'),
                    type: 'success'
                  }) : vm.$message({
                    message: (selections.length - count) + vm.$t('notice.tggyy') + count + vm.$t('notice.tggbkcfyycz'),
                    type: 'warning'
                  });
                  vm.$refs.noticeTable.remoteData();
                } else {
                  vm.$message({
                    message: vm.$t('notice.jzydztsb')
                  });
                }
              }
            });
          } else {
            vm.$message({
              message: vm.$t('notice.ggbkcfyycz'),
              type: 'warning'
            });
            return;
          }
        },

        // 发布按钮
        pubNoticeButtonFn: function () {
          if (this.$refs.noticeTable.selections.length < 1) {
            vm.$message({
              message: vm.$t('notice.qxzggjxfb')
            });
            return false;
          }
          this.pubNoticeFn();
        },
        // 发布
        pubNoticeFn: function () {
          var count = 0;
          var _this = this;
          var commitData = [];
          var selections = _this.$refs.noticeTable.selections;
          for (var i = 0; i < selections.length; i++) {
            if (selections[i].pubSts == 'O' || selections[i].creatorId != yufp.session.userId) {
              count++;
            } else {
              selections[i].pubSts = 'O';
              selections[i].pubOrgId = this.orgId;
              selections[i].pubOrgName = this.orgName;
              selections[i].pubUserId = this.userId;
              selections[i].pubUserName = this.userName;
              commitData.push(selections[i]);
            }
          }
          if (commitData.length > 0) {
            yufp.service.request({
              url: backend.noticeService + '/api/adminsmnotice/pubnotices',
              method: 'post',
              data: JSON.stringify(commitData),
              callback: function (code, message, response) {
                if (code == '0' && response.code == 0) {
                  count == 0 ? _this.$message({
                    message: _this.$t('notice.fbcg')
                  }) : _this.$message({
                    message: (selections.length - count) + _this.$t('notice.tggfbcg') + count + _this.$t('notice.tggbkfb'),
                    type: 'warning'
                  });
                  _this.$refs.noticeTable.remoteData();
                } else {
                  _this.$message({
                    message: _this.$t('notice.fbsb')
                  });
                }
              }
            });
          } else {
            _this.$message({
              message: _this.$t('notice.ggbyxfb'),
              type: 'warning'
            });
            return;
          }
        },


        // 修改保存
        dataNoticeEditFn: function () {
          if (vm.$refs.noticeForm.formModel.reciveRoleName == '') {
            vm.$refs.noticeForm.formModel.reciveRoleId = '';
          }
          vm.$refs.noticeForm.formModel.content = vm.content;
          yufp.service.request({
            url: backend.noticeService + '/api/adminsmnotice/updates',
            method: 'post',
            data: vm.$refs.noticeForm.formModel,
            callback: function (code, message, response) {
              if (code == '0' && response.code == 0) {
                vm.$message({
                  message: vm.$t('notice.xgcg')
                });
                vm.$refs.noticeTable.remoteData();
                vm.dialogVisible = false;
                window.tinymce.get(vm.tinymceId).destroy();
              } else {
                vm.$message({
                  message: vm.$t('notice.xgsb')
                });
              }
            }
          });
        },

        // 新增按钮
        addNoticeRecord: function () {
          this.dialogVisible = true;
          this.roleAllSelect = [];

          // 初始化生成的ID
          this.createdNoticeId = '';
          // 初始化富文本

          // 初始化附件列表参数
          this.initFilesParams = {
            condition: JSON.stringify({
              busNo: ''
            })
          };
          this.creatorFlag = true;
          this.viewType = 'ADD';
          this.$nextTick(function () {
            vm.content = '';
            vm.$refs.noticeForm.resetFn();
            vm.$refs.noticeForm.formModel.isTop = 'N';
            vm.$refs.tinymce.hasChange = false;
            vm.$refs.tinymce.init();
            // 初始化空附件列表
            vm.$refs.filesTable.queryFn();
          });


          // 生成UUID
          yufp.service.request({
            url: backend.noticeService + '/api/adminsmnotice/createNoticeId',
            method: 'get',
            data: null,
            callback: function (code, message, response) {
              if (code == '0' && response.code == 0) {
                vm.createdNoticeId = response.data;

                // 富文本附件操作传参
                vm.busNo = vm.createdNoticeId;

                // 设置附件列表组件传入NOTICEID
                vm.noticeUpLoadBusNo = {
                  busNo: vm.createdNoticeId
                };
                // 初始化附件列表查询时，传入为空
                var files = {
                  condition: JSON.stringify({
                    busNo: vm.createdNoticeId
                  })
                };
                yufp.extend(vm.initFilesParams, files);
                // 获取附件列表
                vm.$refs.filesTable.queryFn();
              } else {
                vm.$message({
                  message: vm.$t('notice.scggsb')
                });
              }
            }
          });
        },

        // 保存新增
        createNotice: function () {
          var model = this.$refs.noticeForm.formModel;
          model.content = vm.content;
          model.pubSts = 'C';
          model.creatorId = this.userId;
          model.creatorName = this.userName;
          model.noticeId = this.createdNoticeId;
          yufp.service.request({
            url: backend.noticeService + '/api/adminsmnotice/createinfo',
            method: 'post',
            data: model,
            callback: function (code, message, response) {
              if (code == '0' && response.code == 0) {
                vm.$message({
                  message: vm.$t('notice.bccg')
                });
                vm.$refs.noticeTable.remoteData();
                vm.dialogVisible = false;
                window.tinymce.get(vm.tinymceId).destroy();
              } else {
                vm.$message({
                  message: vm.$t('notice.bcsb')
                });
              }
            }
          });
        },

        // 批量删除
        dataNoticemultDeleteFn: function () {
          var ids = '';
          var noticeSelecttions = this.$refs.noticeTable.selections;
          if (noticeSelecttions.length > 0) {
            var count = 0;
            for (var i = 0; i < noticeSelecttions.length; i++) {
              // 记录多选用于多删
              if (noticeSelecttions.length === 1) {
                ids = noticeSelecttions[i].noticeId;
              } else {
                if (noticeSelecttions[i].creatorId != yufp.session.userId) {
                  count++;
                } else {
                  ids = ids + ',' + noticeSelecttions[i].noticeId;
                }
              }
            }
          } else {
            vm.$message({
              message: vm.$t('notice.qxzxyscdgg')
            });
            return false;
          }
          if (ids != '') {
            vm.$confirm(vm.$t('notice.qrplscxtgg'), vm.$t('notice.ts'), {
              confirmButtonText: vm.$t('notice.qd'),
              cancelButtonText: vm.$t('notice.qx'),
              type: 'warning'
            }).then(function () {
              yufp.service.request({
                url: backend.noticeService + '/api/adminsmnotice/deletes/' + ids,
                method: 'post',
                data: null,
                callback: function (code, message, response) {
                  if (code == '0' && response.code == 0) {
                    count == 0 ? vm.$message({
                      message: vm.$t('notice.sccg')
                    }) : vm.$message({
                      message: (noticeSelecttions.length - count) + vm.$t('notice.tggsccg') + count + vm.$t('notice.tggbksc'),
                      type: 'warning'
                    });
                    vm.$refs.noticeTable.remoteData();
                  } else {
                    vm.$message({
                      message: vm.$t('notice.scsb')
                    });
                  }
                }
              });
            }).catch(function () {
              return;
            });
          } else {
            vm.$message({
              message: vm.$t('notice.ggbyxsc'),
              type: 'warning'
            });
          }
        },
        // 检查上传文件大小和类型
        beforeAvatarUpload: function (file) {
          var isLt10M = file.size / 1024 / 1024 < 10;
          if (!isLt10M) {
            this.$message.error(this.$t('notice.scwjdxbncg'));
          }
          var index = file.name.lastIndexOf('.');
          var ext = file.name.substr(index + 1);
          var fileType = ['image/jpeg', 'image/gif', 'image/png', 'image/bmp', 'application/vnd.ms-excel', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/pdf', 'application/zip', 'application/msword', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'text/plain', 'application/x-rar'];
          var count = 0;
          var fileCheck = true;
          for (var i in fileType) {
            if (file.type == fileType[i] || ext == 'rar') {
              count++;
            }
          }
          if (count == 0) {
            fileCheck = false;
            this.$message.error(this.$t('notice.scwjywtpwbbgysbgs'));
          }
          return fileCheck && isLt10M;
        },
        close: function () {
          if (window.tinymce.get(this.tinymceId)) {
            window.tinymce.get(this.tinymceId).destroy();
          }
        }

      },
      watch: {
        viewType: function (value) {
          if (value == 'ADD') {
            // 附件列表按钮
            this.uploadVisible = true;
            this.downloadVisible = true;
            this.deleteVisible = true;
            this.updateButtons[0].hidden = false;
            this.updateButtons[1].hidden = true;
            this.formDisabled = false;
            // 日期限制
            this.updateFields[1].fields[1].pickerOptions = this.datePick;
            this.updateFields[1].fields[3].pickerOptions = this.datePick;
          } else if (value == 'UPDATE') {
            this.uploadVisible = true;
            this.downloadVisible = true;
            this.deleteVisible = true;
            this.updateButtons[0].hidden = true;
            this.updateButtons[1].hidden = false;
            this.formDisabled = false;
            // 日期限制
            this.updateFields[1].fields[1].pickerOptions = this.datePick;
            this.updateFields[1].fields[3].pickerOptions = this.datePick;
          } else if (value == 'DETAIL') {
            this.uploadVisible = false;
            this.downloadVisible = true;
            this.deleteVisible = false;
            this.updateButtons[0].hidden = true;
            this.updateButtons[1].hidden = true;
            this.formDisabled = true;
          }
        },
        creatorFlag: function (value) {
          if (value) {
            this.updateFields[1].fields[4].hidden = false;
            this.updateFields[1].fields[5].hidden = false;
          } else {
            this.updateFields[1].fields[4].hidden = true;
            this.updateFields[1].fields[5].hidden = true;
          }
        },
        noticeSelection: function (val) {
          if (val && val.length == 1) {
            var selection = val[0];
            selection.creatorId == yufp.session.userId ? this.creatorFlag = true : this.creatorFlag = false;
            selection.creatorId == yufp.session.userId ? this.buttonEnable = false : this.buttonEnable = true;
          } else {
            this.creatorFlag = true;
            this.buttonEnable = false;
          }
        }

      }
    });
  };


  // 消息处理
  exports.onmessage = function (type, message) {

  };

  // page销毁时触发destroy方法
  exports.destroy = function (id, cite) {

  };
});
